<template>
  <el-dialog :visible.sync="visible" :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false">
    <el-form ref="dataFormRef" :model="dataForm" :rules="dataRules" label-width="100px" @keyup.enter="submitHandle()">
      <el-row>
        <el-col :span="24">
          <el-form-item label="ID" prop="id">
            <el-input v-model="dataForm.id" placeholder="ID" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="业务主键" prop="businessKey">
            <el-input v-model="dataForm.businessKey" placeholder="业务主键" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="附件ID" prop="attachId">
            <el-input v-model="dataForm.attachId" placeholder="附件ID" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="机组" prop="unit">
            <el-input v-model="dataForm.unit" placeholder="机组" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="项目名称" prop="projectName">
            <el-input v-model="dataForm.projectName" placeholder="项目名称" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="环保手续分类" prop="evnFormalitiesCategory">
            <el-input v-model="dataForm.evnFormalitiesCategory" placeholder="环保手续分类" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="批文名称" prop="approvalDocumentName">
            <el-input v-model="dataForm.approvalDocumentName" placeholder="批文名称" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="承诺项" prop="promiseItem">
            <el-input v-model="dataForm.promiseItem" placeholder="承诺项" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="责任部门" prop="responsibleDepartment">
            <el-input v-model="dataForm.responsibleDepartment" placeholder="责任部门" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="责任人员工号" prop="responsiblePersonalName">
            <el-input v-model="dataForm.responsiblePersonalName" placeholder="责任人员工号" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="责任人员姓名" prop="responsiblePersonalCode">
            <el-input v-model="dataForm.responsiblePersonalCode" placeholder="责任人员姓名" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="执行频率" prop="executionFrequency">
            <el-input v-model="dataForm.executionFrequency" placeholder="执行频率" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="完成期限" prop="completionDeadline">
            <el-input v-model="dataForm.completionDeadline" placeholder="完成期限" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="dataForm.remark" placeholder="备注" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="流程状态" prop="processStatus">
            <el-input v-model="dataForm.processStatus" placeholder="流程状态" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="关闭日期" prop="closeDate">
            <el-input v-model="dataForm.closeDate" placeholder="关闭日期" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="创建人工号" prop="createdUserCode">
            <el-input v-model="dataForm.createdUserCode" placeholder="创建人工号" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="创建人姓名" prop="createdUserName">
            <el-input v-model="dataForm.createdUserName" placeholder="创建人姓名" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="创建时间" prop="createdTime">
            <el-input v-model="dataForm.createdTime" placeholder="创建时间" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="修改人工号" prop="updatedUserCode">
            <el-input v-model="dataForm.updatedUserCode" placeholder="修改人工号" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="修改人姓名" prop="updatedUserName">
            <el-input v-model="dataForm.updatedUserName" placeholder="修改人姓名" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="修改时间" prop="updatedTime">
            <el-input v-model="dataForm.updatedTime" placeholder="修改时间" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="删除标志" prop="delFlag">
            <el-input v-model="dataForm.delFlag" placeholder="删除标志" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="submitHandle()">确定</el-button>
    </template>
  </el-dialog>
</template>

<script>
import { useEnvironmental_protection_proceduresApi, useEnvironmental_protection_proceduresSubmitApi } from '@/api/business/environmental_protection_procedures'

export default {
  name: 'AddOrUpdate',
  data() {
    return {
      visible: false,
      dataForm: {
        id: '',
        businessKey: '',
        attachId: '',
        unit: '',
        projectName: '',
        evnFormalitiesCategory: '',
        approvalDocumentName: '',
        promiseItem: '',
        responsibleDepartment: '',
        responsiblePersonalName: '',
        responsiblePersonalCode: '',
        executionFrequency: '',
        completionDeadline: '',
        remark: '',
        processStatus: '',
        closeDate: '',
        createdUserCode: '',
        createdUserName: '',
        createdTime: '',
        updatedUserCode: '',
        updatedUserName: '',
        updatedTime: '',
        delFlag: '' },
      dataRules: {
      }
    }
  },
  methods: {
    init(id) {
      this.visible = true
      this.dataForm.id = ''
      const formInstance = this.$refs.dataFormRef
      if (formInstance) {
        formInstance.resetFields()
      }
      if (id) {
        this.getEnvironmental_protection_procedures(id)
      }
    },
    getEnvironmental_protection_procedures(id) {
      useEnvironmental_protection_proceduresApi(id).then(res => {
        Object.assign(this.dataForm, res.data)
      })
    },
    submitHandle() {
      this.$refs.dataFormRef.validate((valid) => {
        if (!valid) {
          return false
        }
        useEnvironmental_protection_proceduresSubmitApi(this.dataForm).then(() => {
          this.$message.success({
            message: '操作成功',
            duration: 500,
            onClose: () => {
              this.visible = false
              this.$emit('refreshDataList')
            }
          })
        })
      })
    }
  }
}
</script>
